/**   
 * @Title: ResourceService.java 
 * @Package com.betterjr.modules.workflow.snaker.core 
 * @Description: 流程实例操作类
 * @author licz
 * @date 2017年10月30日 下午3:03:48  
 */
package com.betterjr.modules.risk.loanmanage.service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.common.service.BaseService;
import com.betterjr.common.utils.BTAssert;
import com.betterjr.common.utils.BetterDateUtils;
import com.betterjr.common.utils.UserUtils;
import com.betterjr.mapper.pagehelper.Page;
import com.betterjr.modules.risk.loanmanage.dao.PartnershipMapper;
import com.betterjr.modules.risk.loanmanage.entity.Partnership;
import com.betterjr.modules.risk.loanmanage.util.BetterBeanUtils;

@Service
public class PartnershipService extends BaseService<PartnershipMapper, Partnership> {

    public Page<Partnership> listPartnership(final Partnership partnership, final int pageNum, final int pageSize) {
        return this.selectByPage(partnership, pageNum, pageSize, true);
    }

    public Page<Partnership> listPartnership(final Map<String, Object> param, final int pageNum, final int pageSize) {
        final Partnership partnership = new Partnership();
        BetterBeanUtils.copyProperties2Bean(partnership, param);
        BTAssert.notNull(partnership, "参数不允许为空！");
        return listPartnership(partnership, pageNum, pageSize);
    }

    public List<Partnership> listPartnership(final Map<String, Object> param) {
        final Partnership partnership = new Partnership();
        BetterBeanUtils.copyProperties2Bean(partnership, param);
        BTAssert.notNull(partnership, "参数不允许为空！");
        return this.select(partnership);
    }

    public Partnership savePartnership(final Partnership partnership) {

        partnership.setCreatorId(UserUtils.getUser().getId());
        partnership.setCreator(UserUtils.getUser().getName());
        partnership.setCreateDate(Timestamp.valueOf(BetterDateUtils.getDateTime()));
        if (!ObjectUtils.isEmpty(partnership.getId())) {
            this.updateByPrimaryKeySelective(partnership);
        } else {
            final Long baseId = SerialGenerator.getLongValue(Partnership.selectKey);
            partnership.setId(baseId);
            this.insertSelective(partnership);
        }
        return partnership;
    }

    public Partnership savePartnership(final Map<String, Object> param) {
        final Partnership partnership = new Partnership();
        BetterBeanUtils.copyProperties2Bean(partnership, param);
        BTAssert.notNull(partnership, "参数不允许为空！");
        /* final String bankAccountInfo = param.get("bankAccountInfo").toString();
        BTAssert.isTrue(StringUtils.isNotBlank(bankAccountInfo), "bankAccountInfo参数不允许为空！");
        final CustMechBankAccount bank = JSONObject.parseObject(bankAccountInfo, CustMechBankAccount.class);
        BTAssert.notNull(bank, "银行信息不能为空！");
        
        partnership.setAccountName(bank.getBankAccoName());
        partnership.setAccountNo(bank.getBankAcco());
        partnership.setAccountBank(bank.getBankName());
        partnership.setBankNo(bank.getBankNo());
        partnership.setBankAccountId(bank.getId());*/
        return savePartnership(partnership);
    }

}
